package com.walterweimod.auxiliary_attributes.mobeffect;

import com.walterweimod.auxiliary_attributes.attribute.ModAttributes;
import com.walterweimod.auxiliary_attributes.util.ModAttributeUtils;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectCategory;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.AttributeMap;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import org.jetbrains.annotations.NotNull;

import java.util.UUID;

import static com.walterweimod.auxiliary_attributes.util.ModAttributeUtils.getNameAttributeUUID;
import static com.walterweimod.auxiliary_attributes.util.ModAttributeUtils.removeAttributeModifier;

public class Fireman extends MobEffect {
    private static final UUID MAX_HEALTH_UUID = getNameAttributeUUID(
            Attributes.MAX_HEALTH,
            "fireman"
    );

    private static final UUID MAX_HEAL_PERCENT_UUID = getNameAttributeUUID(
            ModAttributes.MAX_HEAL_PERCENT.get(),
            "fireman"
    );

    protected Fireman() {
        super(MobEffectCategory.BENEFICIAL, 0xFF000000);
    }

    @Override
    public @NotNull Component getDisplayName() {
        return new TextComponent("Fireman");
    }

    @Override
    public void addAttributeModifiers(@NotNull LivingEntity p_19478_,
                                      @NotNull AttributeMap p_19479_,
                                      int p_19480_) {
        ModAttributeUtils.addAttributeModifier(
                p_19478_,
                Attributes.MAX_HEALTH,
                0.1D + 0.06D * p_19480_,
                MAX_HEALTH_UUID,
                AttributeModifier.Operation.MULTIPLY_BASE,
                false
        );

        ModAttributeUtils.addAttributeModifier(
                p_19478_,
                ModAttributes.MAX_HEAL_PERCENT.get(),
                - Math.min(20.0D + p_19480_, 65.0D),
                MAX_HEAL_PERCENT_UUID,
                AttributeModifier.Operation.ADDITION,
                false
        );

        super.addAttributeModifiers(p_19478_, p_19479_, p_19480_);
    }

    @Override
    public void removeAttributeModifiers(@NotNull LivingEntity p_19469_,
                                         @NotNull AttributeMap p_19470_,
                                         int p_19471_) {
        removeAttributeModifier(
                p_19469_,
                Attributes.MAX_HEALTH,
                MAX_HEALTH_UUID
        );

        removeAttributeModifier(
                p_19469_,
                ModAttributes.MAX_HEAL_PERCENT.get(),
                MAX_HEAL_PERCENT_UUID
        );

        super.removeAttributeModifiers(p_19469_, p_19470_, p_19471_);
    }
}
